package ren.colorful.learnJava.jdk8.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import org.junit.Test;

public class StreamTest {
	private Logger LOG = Logger.getGlobal();
	
	private List<String> list = new ArrayList<String>();
	
	public StreamTest(){
		for(int i = 0;i < 100;i++){
			list.add("test"+ i);
		}
	}
	
	@Test
	public void demo1(){
		long size = list.stream().filter(name -> name.contains("test")).count();
		LOG.info(String.valueOf(size));
	}
	
	@Test
	public void demo2(){
		long size = 0;
		for(String name : list){
			if(name.contains("test")){
				size ++;
			}
		}
		LOG.info(String.valueOf(size));
	}
	
	@Test
	public void demo3(){
		LOG.info(String.valueOf(list.stream().filter(name -> {
			String flag = name.substring(0, 3);
			if("test".equals(flag)){
				return true;
			}
			return false;
		}).count()));
	}
	
}
